import Vue from 'vue'
import router from '@/router'
import qs from 'qs'


Vue.prototype.$myUtils = {
    OpenNewWindow: (path, query) => {
        // router.push({ path, query })

        let routerJump = router.resolve({
            path,
            query
        });
        window.open(routerJump.href, "_blank");

        // window.open(`${process.env.VUE_APP_BASE_URL}#${path}${JSON.stringify(query) == '{}' ? '' : '?'}${qs.stringify(query)}`);
    },
    fillWithZeros(origin, length, position = true) {
        origin = String(origin)
        return length - origin.length > 0
            ? (position
                ? '0'.repeat(length - origin.length) + origin
                : origin + '0'.repeat(length - origin.length))
            : origin
    }
}


String.prototype.$fillWithZeros = function (length, position = true) {
    return length - this.length > 0
        ? (position
            ? '0'.repeat(length - this.length) + this
            : this + '0'.repeat(length - this.length))
        : this
}
Number.prototype.$fillWithZeros = function (length, position = true) {
    let that = String(this);
    return length - that.length > 0
        ? (position
            ? '0'.repeat(length - that.length) + that
            : that + '0'.repeat(length - that.length))
        : that;
}
